﻿Imports AForge.Imaging.Filters
Imports AForge
Imports System.Drawing
Imports UCBase

Public Class LightAmpB
    Implements I_ImageExchange
    Private WithEvents Inp As I_ImageExchange
    Private Backpic As New BackgroundCreator
    Private Mov As New Mover
    Private SourceBitmap As System.Drawing.Bitmap
    Private OverLay As Bitmap
    Private DestBitmap As System.Drawing.Bitmap
    Private CurrentCount As Integer = 0
    Private Sub MoveToFilter()
        For c = 1 To KnobControl1.Value
            Dim BM As New Bitmap(SourceBitmap)
            Dim BMB As New Bitmap(SourceBitmap)
            Dim filter As Add = New Add(BM)
            DestBitmap = filter.Apply(BMB)
            BM.Dispose()
            BMB.Dispose()
            SourceBitmap = DestBitmap
        Next c

    End Sub

    Public Event ImageOut(ByVal Image As System.Drawing.Bitmap) Implements I_ImageExchange.ImageOut1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.BackgroundImage = Backpic.CreatePic(Me.Width, Me.Height, Color.MediumSlateBlue)
        Mov.Connect(Me)
        KnobControl1.ContainerColor = Backpic.FaceColor
        KnobControl1.Refresh()
    End Sub
    Private Sub Socket1_Connect() Handles Socket1.Connect
        Dim S As Socket = Socket1.Remote
        Inp = S.Parent
    End Sub

    Private Sub UniversalColorFilter_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Width = 255
        Me.Height = 140
    End Sub

    Private Sub Inp_ImageOut(ByVal Image As System.Drawing.Bitmap) Handles Inp.ImageOut1
        SourceBitmap = Image
        MoveToFilter()
        RaiseEvent ImageOut(DestBitmap)
    End Sub

    Private Sub KnobControl1_ValueChanged(ByVal Sender As Object) Handles KnobControl1.ValueChanged
        ProgressBar1.Maximum = KnobControl1.Value
        CurrentCount = 0
        ProgressBar1.Value = 0
    End Sub

    Private Sub Socket1_Disconnected() Handles Socket1.Disconnected
        Inp = Nothing
    End Sub
    Private Sub Socket1_EnableStateChanged(ByVal State As Boolean) Handles Socket1.EnableStateChanged
        Socket2.SocketsEnable = Socket1.SocketsEnable
        If Socket1.SocketsEnable = False Then
            CurrentCount = 0
            ProgressBar1.Value = 0
        End If
    End Sub
End Class
